var app=getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: { 
    pings:{
      type:Array,
      value:[]
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    zheHeight:'',
    tanchuDis:false,
    courseName:'',
    nowPrice:'', 
    oldPrice:'',
    id:'',
    courseIngtroduce:'',
    coursePosition:'',
  },
  
  attached:function(){
    var that=this
    wx.getSystemInfo({
      success: function(res) {
        that.setData({
          zheHeight:res.windowHeight
        })
      }
    })
   
  },
  /**
   * 组件的方法列表
   */
  methods: {
    changeTanchu:function(event){
      this.setData({
        tanchuDis:false
      })
    },
    getAssembleContent:function(event){
      console.log(event)
   
      var id=event.currentTarget.dataset.id
      var that=this
      that.setData({
        tanchuDis:true,
        id:id
      })
      wx.request({
        url: app.globalData.baseUrl+'mechanism/assemble/'+id,
        method:'get',
        header:{
          'cookie':'JSESSIONID='+wx.getStorageSync('sessionID')
        },
        success:function(res){
          var resData=res.data.data
          that.setData({
            courseName:resData.title,
            courseIngtroduce:resData.introduce,
            nowPrice:resData.priceNow,
            oldPrice:resData.priceOld,
            coursePosition:resData.position
          })
        }
      })
    },  
    joinAssemble: function (event) {
      var that = this
      var id=event.currentTarget.dataset.id
      var courseName=event.detail.courseName
      wx.showModal({
        title: '',
        content: '是否参加该拼团',
        success: function (res) {
          if (res.confirm) {
         
            wx.request({
              url: app.globalData.baseUrl + 'mechanism/assemble/' + id,
              method: 'POST',
              header: {
                'content-type': 'application/x-www-form-urlencoded',
                'cookie': 'JSESSIONID=' + wx.getStorageSync('sessionID')
              },
              success: function (res) {
                console.log(res)
                if (res.data.code == 0) {
                  wx.showToast({
                    title: '报名成功',
                    mask: true,
                    duration: 3000
                  })
                  wx.navigateTo({
                    url: '/xiaoxi/chat/chat?id=' + that.data.id + '&news=' + '您好我想报名你们机构的 ' + courseName + ' 拼团',
                  })

                } else if(res.data.code==1102){
                    wx.showModal({
                      title: '',
                      content: '您已经参加过该拼团，不能继续参加',
                    })
                }
                
                else{
                  wx.showToast({
                    title: '报名失败',
                    icon: 'none',
                    mask: true,
                    duration: 3000
                  })
                }
              }
            })
          }
        }
      })
    }
  }
})
